home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group93c.txt
/
000015_icon-group-sender _Tue Jul 20 14:39:42 1993.msg
< prev
next >
Wrap
Internet Message Format
|
1994-02-02
|
1KB
Received: by cheltenham.cs.arizona.edu; Tue, 20 Jul 1993 19:43:14 MST
Date: Tue, 20 Jul 93 14:39:42 PDT
From: alex@laguna.Metaphor.COM (Bob Alexander)
Message-Id: <9307202139.AA17977@laguna.Metaphor.COM>
To: icon-group@cs.arizona.edu
Subject: Re: Mystery about "every"
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
>From: Ken Walker <kwalker@shara.premenos.sf.ca.us>
>> Paul_Abrahams@MTS.cc.Wayne.edu writes
>>
>> ...
>> This program produced the output 83, as expected. But I then replaced
>> the "every" statement by the following one, which I thought to be more
>> elegant:
>>
>> every retval := 8 * retval + ord(!s) - ord("0")
>>
>> Now the output of the program is 3 (the last digit), not 83.
>
>Backtracking only goes as far as the generator !s. The expression
>
> 8 * retval
>
>is not reeveluated. The original value of 0 is used in every
>iteration.
Try rephrasing it as:
every retval := ord(!s) - ord("0") + 8 * retval
It works.
You can run into some rather non-intuitive stuff using this "short
form" of every -- you have to think hard about the order of evaluation
and exactly which parts of the expression will be re-evaluated.
Its safer, and probably more transparent, to use the longer form with
the auxiliary variable -- but not as cute.
-- Bob Alexander
Metaphor Computer Systems (415) 966-0751 alex@metaphor.com
====^=== Mountain View, CA ...{uunet}!{decwrl,apple}!metaphor!alex